<?php
/**
 * @param Protty
 * @url www.pder.org
 **/
if ($_GET['c'] == 'update') {
    $_VERSION = '2.7.0';
    $VERSION = @file_get_contents("http://pocent.version.key.pder.org/version.php");
    @preg_match_all("/<POCENT_VER>([\s\S]+?)<\/POCENT_VER><POCENT_NEW_URL>([\s\S]+?)<\/POCENT_NEW_URL><POCENT_SQL>([\s\S]+?)<\/POCENT_SQL>/", $VERSION, $_SERVER_VERSION);
    $POCENT_VERSION = $_SERVER_VERSION['1']['0']; // 版本号
    $POCENT_NEW_DOWN = $_SERVER_VERSION['2']['0']; // 下载地址
    $POCENT_SQL = $_SERVER_VERSION['3']['0']; // 更新数据库
    if ($_VERSION !== $POCENT_VERSION) {
        $zip = file_get_contents($POCENT_NEW_DOWN);
        $down = file_put_contents("1.zip", $zip);
        if ($down) {
            $new = new ZipArchive();
            $res = $new->open('1.zip');
            if ($res === TRUE) {
                $new->extractTo('../');
                $new->close();
                if (!empty($POCENT_SQL)){
                    $link = mysql_connect($config['host'],$config['username'],$config['password']) or die("数据库连接失败了哟!");
                    $db = mysql_select_db($config['dbname']) or die("没有找到这个数据库哦~");
                    $charset = mysql_query("set names utf8");
                    $mysql = mysql_query($POCENT_SQL);
                    if ($mysql){
                        echo <<<end
<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;font-size:24px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px } a,a:hover,{color:blue;}</style><div style="padding: 24px 48px;"> <h1>:)</h1><p><b>数据升级完成,现在,你只需要几秒就可以体验新功能!</b></p>
<meta http-equiv='refresh' content='3;url=../'>
end;
                        exit;
                    }
                }
                echo <<<end
<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;font-size:24px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px } a,a:hover,{color:blue;}</style><div style="padding: 24px 48px;"> <h1>:)</h1><p><b>更新成功,现在,你只需要几秒就可以体验新功能!</b></p>
<meta http-equiv='refresh' content='3;url=../'>
end;
            } else {
                echo '更新失败, 请检查是否有可写权限,  错误代码:' . $res;
            }
        } else {
            echo "no";
        }
    }else{
        echo <<<end
<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;font-size:24px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px } a,a:hover,{color:blue;}</style><div style="padding: 24px 48px;"> <h1>:(</h1><p><b>你已经是最新版，无需升级!</b></p>
<meta http-equiv='refresh' content='3;url=../'>
end;
    }
}